// pages/songList/songList.js
import request from '../../utils/request'
import PubSub from 'pubsub-js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
	songGroupList: [],		// 歌单标签数据
	navId: '',				// 导航标识
	newPlayList: [],		// 精选歌单数据
	goodPlayList: [],		// 精品歌单
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	this.getPlayListCategory();
	this.getNewPlayList();
	this.getGoodPlayList();
  },
	
	// 获取歌单分类
	async getPlayListCategory(){
		let PlayListCategoryData =  await request('/playlist/catlist');
		// console.log(PlayListCategoryData);
		let index = 0;
		let songGroupList = PlayListCategoryData.sub.slice(0,14).map(item => {
			item.id = index++;
			return item;
		})
		this.setData({
			songGroupList
		})
	},
	
	// 获取精选歌单
	async getNewPlayList(){
		let newPlayListData =  await request('/top/playlist',{limit:10,order:'new'});
		this.setData({
			newPlayList: newPlayListData.playlists.splice(0,9)
		})
	},
	
	// 获取部分精品歌单
	async getGoodPlayList(){
		let goodPlayListData =  await request('/top/playlist/highquality',{before:1503639064232});
		// console.log(goodPlayListData);
		let goodPlayList = goodPlayListData.playlists;
		this.setData({
			goodPlayList
		})
	},
	
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
	
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})